import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  // 重定向到login页面
  {
    path: "/",
    redirect: "/login",
  },
  {
    path: '/login',
    name: 'login',
    component: () => import("../views/login.vue")
  },
  {
    path: '/home',
    name: 'home',
    component: () => import("../views/Home.vue"),
    children: [
      {
        path: '/home/user',
        name: 'user',
        component: () => import("../views/user/index.vue"),
      },
      {
        path: '/home/advertisement',
        name: 'advertisement',
        component: () => import("../views/advertisement/index.vue"),
      },
      {
        path: '/home/shenhe',
        name: 'shenhe',
        component: () => import("../views/advertisement/shenhe.vue"),
      }
    ]
  },
]


// router.beforeEach((to, from, next) => {
//   if (to.path == '/login') {
//     next();
//   } else {
//     if (window.localStorage.getItem('token')) {
//       next()
//     } else {
//       alert('请先登入')
//       next('/login');
//     }
//   }
// })


const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
